//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Configuration;
using EntLibContrib.Resource.Configuration;
#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Resource.Tests
{
	[TestClass]
	public class InternalResourceConfigurationViewFixture
	{
		private static ResourceConfigurationView view;
		private static InternalResourceConfigurationSource source;

		[TestInitialize]
		public void CreateView ()
		{
			source = new InternalResourceConfigurationSource();
			view = new ResourceConfigurationView(source);
		}

		[TestMethod]
		public void CheckWeCanGetNamedResourceManagerData ()
		{
			ResourceManagerData resourceManagerData = view.GetResourceManagerData("InternalResourceManager");
			Assert.IsNotNull(resourceManagerData);
		}

		[TestMethod]
		public void CheckWeCanGetNamedResourceProviderData ()
		{
			AssemblyResourceProviderData internalResourceProviderData = (AssemblyResourceProviderData)view.GetResourceProviderData("InternalResourceProvider");
			Assert.IsNotNull(internalResourceProviderData);
		}

		[TestMethod]
		[ExpectedException(typeof(ConfigurationErrorsException))]
		public void NullResourceManagerInstanceThrowsException ()
		{
			view.GetResourceManagerData(null);
		}

		[TestMethod]
		[ExpectedException(typeof(ConfigurationErrorsException))]
		public void EmptyResourceManagerInstanceThrowsException ()
		{
			view.GetResourceManagerData(String.Empty);
		}

		[TestMethod]
		[ExpectedException(typeof(ConfigurationErrorsException))]
		public void BadResourceManagerInstanceThrowsException ()
		{
			view.GetResourceManagerData("BadResourceManagerInstance");
		}

		[TestMethod]
		[ExpectedException(typeof(ConfigurationErrorsException))]
		public void NullResourceProviderInstanceThrowsException ()
		{
			view.GetResourceProviderData(null);
		}

		[TestMethod]
		[ExpectedException(typeof(ConfigurationErrorsException))]
		public void EmptyResourceProviderInstanceThrowsException ()
		{
			view.GetResourceProviderData(String.Empty);
		}

		[TestMethod]
		[ExpectedException(typeof(ConfigurationErrorsException))]
		public void BadResourceProviderInstanceThrowsException ()
		{
			view.GetResourceProviderData("BadResourceProviderInstance");
		}

		[TestMethod]
		public void CheckDefaultResourceManager ()
		{
			Assert.AreEqual("InternalResourceManager", view.DefaultResourceManager);
		}
	}
}